home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.008.List.Line.Edit / Lists.aii next >
Encoding:
Text File  |  1990-06-24  |  41.6 KB  |  1,719 lines  |  [TEXT/MPS ]

  1. *******************************************************************************
  2. *
  3. * List Manager/LineEdit Demo
  4. *
  5. * (C)  Copyright Apple Computer, Inc. 1988-1990
  6. * All rights reserved.
  7. *
  8. * Developer Technical Support Apple II Sample Code
  9. *
  10. * by Keith Rollin and Jim Mensch
  11. *
  12. * This program demonstrates the use of lists and LineEdit items in a window. It
  13. * uses controls to create, rename, remove and sort items in a list, and uses a
  14. * LineEdit item to enter new and rename old items. Cut, Copy, Paste, and Clear
  15. * are supported.
  16. *
  17. *******************************************************************************
  18.     eject
  19.     
  20. **********************************************************************
  21. *                                                                    *
  22. *     This program and its derivatives are licensed only for         *
  23. *     use on Apple computers.                                        *
  24. *                                                                    *
  25. *     Works based on this program must contain and                   *
  26. *     conspicuously display this notice.                             *
  27. *                                                                    *
  28. *     This software is provided for your evaluation and to           *
  29. *     assist you in developing software for the Apple IIGS           *
  30. *     computer.                                                      *
  31. *                                                                    *
  32. *     DISCLAIMER OF WARRANTY                                         *
  33. *                                                                    *
  34. *     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT                       *
  35. *     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,               *
  36. *     WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS             *
  37. *     FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO             *
  38. *     THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH            *
  39. *     YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND            *
  40. *     NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)               *
  41. *     ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,             *
  42. *     REPAIR OR CORRECTION.                                          *
  43. *                                                                    *
  44. *     Apple does not warrant that the functions                      *
  45. *     contained in the Software will meet your requirements          *
  46. *     or that the operation of the Software will be                  *
  47. *     uninterrupted or error free or that defects in the             *
  48. *     Software will be corrected.                                    *
  49. *                                                                    *
  50. *     SOME STATES DO NOT ALLOW THE EXCLUSION                         *
  51. *     OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY              *
  52. *     NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC            *
  53. *     LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS                *
  54. *     WHICH VARY FROM STATE TO STATE.                                *
  55. *                                                                    *
  56. *                                                                    *
  57. **********************************************************************
  58.     eject
  59.     
  60.     case   on
  61.     PRINT  NOGEN,NOHDR
  62.     STRING ASIS
  63.  
  64.     PRINT PUSH,OFF
  65.     INCLUDE 'M16.Util2'
  66.     INCLUDE 'M16.ProDOS'
  67.     INCLUDE 'M16.MiscTool'
  68.     INCLUDE 'M16.QUICKDRAW'
  69.     INCLUDE 'E16.Quickdraw'
  70.     INCLUDE 'M16.MEMORY'
  71.     INCLUDE 'E16.Memory'
  72.     INCLUDE 'M16.EVENT'
  73.     INCLUDE 'E16.EVENT'
  74.     INCLUDE 'M16.LOCATOR'
  75.     INCLUDE 'M16.Menu'
  76.     INCLUDE 'M16.Control'
  77.     INCLUDE 'E16.Control'
  78.     INCLUDE 'M16.Window'
  79.     INCLUDE 'E16.Window'
  80.     INCLUDE 'M16.Dialog'
  81.     INCLUDE 'E16.Dialog'
  82.     INCLUDE 'M16.LineEdit'
  83.     INCLUDE 'M16.IntMath'
  84.     INCLUDE 'M16.Scrap'
  85.     INCLUDE 'M16.Desk'
  86.     INCLUDE 'M16.Texttool'
  87.     Include 'E16.List'
  88.     Include 'M16.List'
  89.     PRINT POP
  90.  
  91. *******************************************************************************
  92. *
  93. *    Equates used in this program.
  94. *
  95. *******************************************************************************
  96. DPHandle    equ 0    ; Handle to Tool Direct Page area
  97. DPPointer    equ DPHandle+4    ; Pointer to Tool Direct Page area
  98. deref    equ DPPointer+4    ; Temporary Handle dereference area
  99. TempLong    equ deref+4
  100. TempWord    equ TempLong+4
  101.  
  102. ScreenMode    equ mode640
  103. ScreenWidth    equ 640
  104.  
  105.  
  106.     EJECT
  107. *******************************************************************************
  108. *
  109. Main    PROC
  110. *
  111. * Description:    This is the main routine. It calls routines to Initialize
  112. *    the tools, initialize application specific data, run the
  113. *    main EventLoop, close the application, and close the tools.
  114. *    Then it calls the ProDOS Quit command.
  115. *
  116. *
  117. * Inputs:    NONE
  118. *
  119. * Outputs:    NONE
  120. *
  121. * External Refs:
  122.     import InitTools
  123.     import InitApp
  124.     import EventLoop
  125.     import CloseApp
  126.     import CloseTools
  127.     import QuitParms
  128. *
  129. * Entry Points:    NONE
  130. *
  131. *******************************************************************************
  132.  
  133.     jsr InitTools
  134.     jsr InitApp
  135.  
  136.     _ShowCursor
  137.  
  138.     jsr EventLoop
  139.  
  140.     jsr CloseApp
  141.     jsr CloseTools
  142.  
  143.     _Quit QuitParms
  144.  
  145.     ENDP
  146.  
  147.     EJECT
  148. *******************************************************************************
  149. *
  150. Globals    Record
  151. *
  152. * Description:    Holder of all of our data.
  153. *
  154. *
  155. * Inputs:    N/A
  156. *
  157. * Outputs:    N/A
  158. *
  159. * External Refs:
  160.     import PrUpdate
  161.     import PrOldUpdate
  162. *
  163. * Entry Points:
  164.     export QuitParms    ; used by Main
  165. *
  166. *******************************************************************************
  167. *
  168. * Standard global data
  169. *
  170. *******************************************************************************
  171.  
  172. TitleString    str 'Apple IIgs List Mgr/LineEdit Example Application'
  173. AutString    str 'By Rollin and Mensch Apple DTS -- Version: 3.0'
  174. VersString    str 'Copyright (c) 1988-1990 Apple Computer'
  175.  
  176. MenuHeight    ds.B 2    ; Stored height of menu bar
  177. MyID    ds.B 2    ; Application ID
  178. MyDP    ds.B 2    ; My direct page storage
  179.  
  180. QuitFlag    ds.W 1
  181. QuitParms    dc.L 0    ; Pathname of next app
  182.     dc.W $00    ; flags
  183.  
  184. EventRecord
  185. EventWhat    ds.B 2
  186. EventMessage    ds.B 4
  187. EventWhen    ds.B 4
  188. EventWhere    ds.B 4
  189. EventModifiers    ds.B 2
  190. TaskData    ds.B 4
  191. TaskMask    dC.L $0000FFFF
  192.  
  193.     EJECT
  194. *******************************************************************************
  195. *
  196. * Application specific global data
  197. *
  198. *******************************************************************************
  199.  
  200. ; This is a list of pointers to the text that is used to create our menus. It
  201. ; is used by InitApp to find all of the menu templates and use them to create
  202. ; our menubar. This loop loads MenuPtrLen-4 into an index, gets the
  203. ; corresponding menu template pointer in this table, and uses that in a
  204. ; NewMenu call. It then decrements the index by 4, and repeats the procees
  205. ; until the index is negative.
  206.  
  207. MenuPtr    dc.l AppMenu
  208.     dc.l FileMenu
  209.     dc.l EditMenu
  210. MenuPtrLen    equ *-MenuPtr
  211.  
  212.  
  213. ; Menu list: menu items should be numbered consecutivly starting from 250.
  214. ; As a convention, use 256 as about and 257 as Quit.
  215.  
  216. AppMenu    dc.B '$$@\XN1',$0D
  217.     dc.B '--About List Manager/LineEdit Demo...\N256V',$00
  218.     dc.B '.'
  219. FileMenu    dc.B '$$  File  \N2',$00
  220.     dc.B '--Close Document\N255DV',$00
  221.     dc.B '--Quit\N257*Qq',$00
  222.     dc.B '.'
  223. EditMenu    dc.B '$$  Edit  \N3',$00
  224.     dc.B '--Undo\N250*ZzVD',$00
  225.     dc.B '--Cut\N251*Xx',$00
  226.     dc.B '--Copy\N252*Cc',$00
  227.     dc.B '--Paste\N253*Vv',$00
  228.     dc.B '--Clear\N254',$00
  229.     dc.b '.'
  230.  
  231. ErrOut    ds.B 4
  232. TempSave    ds.B 4
  233. TempHndl    ds.B 4
  234.  
  235. ;
  236. ;   Control definitions for use with new control
  237. ;
  238. NumCtrls    dc.W 5
  239. MyCtrlList    dc.L NewBRec,DelBRec,RepBRec,RstBRec,SortBRec
  240.  
  241. MyCtlHdls
  242. NewBHdl    ds.B 4    ; storage for returned handles
  243. DelBHdl    ds.B 4
  244. RepBHdl    ds.B 4
  245. RstBHdl    ds.B 4
  246. SortBHdl    ds.B 4
  247. LEHandle    ds.B 4
  248.  
  249. NewBTitle    str 'New Entry'
  250. DelBTitle    str 'Remove'
  251. RepBTitle    str 'Replace'
  252. RstBTitle    str 'UnHilite'
  253. SortBTitle    str 'Sort'
  254.  
  255. NewBRect    dc.W 10,250,25,350
  256. DelBRect    dc.W 30,250,45,350
  257. RepBRect    dc.W 50,250,65,350
  258. RstBRect    dc.W 70,250,85,350
  259. SortBRect    dc.W 90,250,105,350
  260. destRect    dc.w 100,20,110,224
  261. viewRect    dc.w 97,10,113,234
  262.  
  263. NewBRec
  264.     dc.L 0
  265.     dc.L 1
  266.     dc.L simpleProc    ; defproc = simple button
  267.     dc.W 0,0    ; no params
  268.     dc.W 1    ; starting value
  269.     dc.W boldButton    ; control flags
  270.     dc.L NewBTitle    ; pointer to title string
  271.     dc.L NewBRect    ; pointer to bounds rect
  272. cRecSize    equ *-NewBRec    ; size of my control record
  273.  
  274. DelBRec
  275.     dc.L 0    ; color table pointer
  276.     dc.L 2    ; refcon ( control dispatch number )
  277.     dc.L simpleProc    ; defproc = simple button
  278.     dc.W 0,0    ; no params
  279.     dc.W 1    ; starting value
  280.     dc.W simpRound    ; control flags
  281.     dc.L DelBTitle    ; pointer to title string
  282.     dc.L DelBRect    ; pointer to bounds rect
  283.  
  284.  
  285. RepBRec
  286.     dc.L 0    ; color table pointer
  287.     dc.L 3    ; refcon ( control dispatch number )
  288.     dc.L simpleProc    ; defproc = simple button
  289.     dc.W 0,0    ; no params
  290.     dc.W 1    ; starting value
  291.     dc.W simpRound    ; control flags
  292.     dc.L RepBTitle    ; pointer to title string
  293.     dc.L RepBRect    ; pointer to bounds rect
  294.  
  295. RstBRec
  296.     dc.L 0    ; color table pointer
  297.     dc.L 4    ; refcon ( control dispatch number )
  298.     dc.L simpleProc    ; defproc = simple button
  299.     dc.W 0,0    ; no params
  300.     dc.W 1    ; starting value
  301.     dc.W simpRound    ; control flags
  302.     dc.L RstBTitle    ; pointer to title string
  303.     dc.L RstBRect    ; pointer to bounds rect
  304.  
  305. SortBRec
  306.     dc.L 0    ; color table pointer
  307.     dc.L 6    ; refcon ( control dispatch number )
  308.     dc.L simpleProc    ; defproc = simple button
  309.     dc.W 0,0    ; no params
  310.     dc.W 1    ; starting value
  311.     dc.W simpRound    ; control flags
  312.     dc.L SortBTitle    ; pointer to title string
  313.     dc.L SortBRect    ; pointer to bounds rect
  314.  
  315.  
  316. FullRect    dc.W 0,0,120,400
  317. ListCtlHndl    ds.B 4
  318.  
  319. MemberSize    equ 10
  320.  
  321. MyList        ; List record
  322. ListRect    dc.W 10,10,92,210    ; list is 200x80
  323. MLNum    dc.W 5    ; number of members in the list
  324.     dc.W 8    ; max seen at once
  325.     dc.W selectOnlyOne    ; single selection/pascal strings
  326.     dc.W 1    ; list start
  327.     dc.L 0    ; list control handle
  328.     dc.L 0    ; no list draw
  329.     dc.W 10    ; list member height
  330.     dc.W MemberSize    ; list record size
  331.     dc.L MyData    ; pointer to member list
  332.     dc.L 5    ; list ref con (control dispatch number)
  333.     dc.L 0    ; color table pointer (default colors)
  334.  
  335. ;
  336. ; These are the data records for each member of the list. Each one consists of:
  337. ;      - a pointer to the string to be printed
  338. ;      - a word of bit flags (only the lower byte is used; the upper byte is
  339. ;        used as padding to make data access easier.
  340. ;      - a 4 byte space to hold a handle for those items whose names have been
  341. ;        stored in the heap with the Memory Manager
  342. ; We define only 5 members initially. However, we reserve space in the member
  343. ; record array for 30 members total.
  344.  
  345. MyData    dc.L member1
  346.     dc.w 0
  347.     dc.l 0
  348.     dc.L member2
  349.     dc.w 0
  350.     dc.l 0
  351.     dc.L member3
  352.     dc.w 0
  353.     dc.l 0
  354.     dc.L member4
  355.     dc.w 0
  356.     dc.l 0
  357.     dc.L member5
  358.     dc.w 0
  359.     dc.l 0
  360.     ds.B 25*MemberSize    ; and at the end, room for 25 more
  361. MyDataTSize    equ *-MyData
  362.  
  363. member1    str 'Member 1'
  364. member2    str 'Member 2'
  365. member3    str 'Member 3'
  366. member4    str 'Member 4'
  367. member5    str 'Member 5'
  368.  
  369. MyWindow    dc.W WindEnd-*    ; size of paramBlock
  370.     dc.W %0010000000100000 ; frame bits : alert, vis
  371.     dc.L 0    ; no title bar, no title...
  372.     dc.L 0    ; ref con 0
  373.     dc.W 0,0,0,0    ; zoomed rect
  374.     dc.L 0    ; color table = default
  375.     dc.W 0,0    ; scroll bar XY origin
  376.     dc.W 0,0    ; no scroll no max...
  377.     dc.W 0,0    ; No zooming...
  378.     dc.W 0,0    ; no scrolling
  379.     dc.W 0,0    ; no paging....
  380.     dc.L 0    ; no info bar, no ref con
  381.     dc.W 0    ; info bar height (none...)
  382.     dc.L 0    ; Frame defproc, NIL=standard
  383.     dc.L 0    ; no info bar def proc
  384.     dc.L 0    ; no auto updates..(yet)
  385.     dc.W 20,20,140,420    ; bounds rect...
  386.     dc.L $FFFFFFFF    ; plane= on top...
  387.     dc.L 0    ; NIL storage pointer
  388. WindEnd    equ *
  389. WindPointer    ds.B 4
  390.  
  391.     EndR
  392.  
  393.  
  394.     EJECT
  395. *******************************************************************************
  396. *
  397. InitApp    PROC
  398. *
  399. * Description:    Perform any application specific initialization.
  400. *
  401. * Inputs:    NONE
  402. *
  403. * Outputs:    NONE
  404. *
  405. * External Refs:    
  406.     import CreateList
  407.     import CreateCtrls
  408.     import NoSelection
  409. *
  410. * Entry Points:    NONE
  411. *
  412. *******************************************************************************
  413.     With Globals
  414.  
  415.     stz QuitFlag
  416.  
  417.     pha
  418.     pha
  419.     PushLong #MyWindow
  420.     _NewWindow
  421.     PullLong WindPointer
  422.  
  423.     PushLong WindPointer
  424.     _SetPort
  425.  
  426.     jsr CreateList    ; make a list in the window
  427.     jsr CreateCtrls
  428.     jsr NoSelection    ; reset the buttons to unselected
  429.  
  430.     PushWord #255    ; deactivate the delete button
  431.     PushLong NewBHdl    ; handle to the delete button
  432.     _HiLiteControl
  433.  
  434.     PushWord #25    ; set the size of LineEdit's
  435.     _LESetScrapLen    ; scrap to 25 characters
  436.  
  437.     rts
  438.     ENDP
  439.  
  440.     EJECT
  441. *******************************************************************************
  442. *
  443. CloseApp    PROC
  444. *
  445. * Description:    Close down things. This disposes of all items and memory
  446. *    that we allocated.
  447. *
  448. *
  449. * Inputs:    NONE
  450. *
  451. * Outputs:    NONE
  452. *
  453. * External Refs:    NONE
  454. *
  455. * Entry Points:    NONE
  456. *
  457. *******************************************************************************
  458.     With Globals
  459.  
  460.     rts
  461.     ENDP
  462.  
  463.     EJECT
  464. *******************************************************************************
  465. *
  466. EventLoop    PROC
  467. *
  468. * Description:    Main Event Loop. Handle things until user selects Quit.
  469. *
  470. *
  471. * Inputs:    NONE
  472. *
  473. * Outputs:    NONE
  474. *
  475. * External Refs:
  476.     import MenuSelect
  477.     import Ignore
  478.     import doUpdate
  479.     import InContent
  480.     import doActivate
  481.     import doKey
  482. *
  483. * Entry Points:    NONE
  484. *
  485. *******************************************************************************
  486.     With Globals
  487.  
  488.     PushLong LEHandle    ; flash the LineEdit cursor
  489.     _LEIdle
  490.  
  491.     pha    ; Push on space for TaskMaster result
  492.     PushWord #everyEvent ; GetNextEvent mask
  493.     PushLong #EventRecord ; Pointer to Event Record
  494.     _TaskMaster
  495.  
  496.     pla    ; Get TaskMaster result
  497.     beq EventLoop    ; Remove if you want to use null events
  498.     asl A    ; Turn it into an index
  499.     tax
  500.     jsr (TaskTable,x)    ; Call appropriate event handler
  501.  
  502.     lda QuitFlag    ; Quit selected?
  503.     beq EventLoop    ; no - keep looping
  504.  
  505.     rts    ; yes- leave the program
  506.  
  507. TaskTable    dc.W Ignore    ; 0 Null
  508.     dc.W Ignore    ; 1 MouseDown
  509.     dc.W Ignore    ; 2 MouseUp
  510.     dc.W doKey    ; 3 KeyDown
  511.     dc.W Ignore    ; 4 undefined
  512.     dc.W doKey    ; 5 AutoKey
  513.     dc.W doUpdate    ; 6 Update
  514.     dc.W Ignore    ; 7 undefined
  515.     dc.W doActivate    ; 8 Activate
  516.     dc.W Ignore    ; 9 Switch
  517.     dc.W Ignore    ; 10 Desk accessory
  518.     dc.W Ignore    ; 11 Device driver
  519.     dc.W Ignore    ; 12 ap
  520.     dc.W Ignore    ; 13 ap
  521.     dc.W Ignore    ; 14 ap
  522.     dc.W Ignore    ; 15 ap
  523.     dc.W Ignore    ; TASK 0 indesk
  524.     dc.W MenuSelect    ; TASK 1 in menuBar
  525.     dc.W Ignore    ; TASK 2 in system window
  526.     dc.W InContent    ; TASK 3 in content
  527.     dc.W Ignore    ; TASK 4 in Drag
  528.     dc.W Ignore    ; TASK 5 in grow
  529.     dc.W Ignore    ; TASK 6 in goaway
  530.     dc.W Ignore    ; TASK 7 in zoom
  531.     dc.W Ignore    ; TASK 8 in info bar
  532.     dc.W MenuSelect    ; TASK 9 in special    menu
  533.     dc.W Ignore    ; TASK 10 in NDA
  534.     dc.W Ignore    ; TASK 11 in frame
  535.     dc.W Ignore    ; TASK 12 in drop
  536.  
  537.     ENDP
  538.  
  539.     EJECT
  540. *******************************************************************************
  541. *
  542. MenuSelect    PROC
  543. *
  544. * Description:    This routine is called when TaskMaster returns a menu
  545. *    event. It takes the menu item that was hit and calculates
  546. *    an offset into the menu dispatch table. It then calls that
  547. *    routine and unhilites the menu when it is done.
  548. *
  549. * Inputs:    TaskData holds menu item selected.
  550. *
  551. * Outputs:    NONE
  552. *
  553. * External Refs:
  554.     import Ignore
  555.     import doAbout
  556.     import doQuit
  557.     import doCut
  558.     import doCopy
  559.     import doPaste
  560.     import doClear
  561. *
  562. * Entry Points:    NONE
  563. *
  564. *******************************************************************************
  565.     With Globals
  566.  
  567.     lda TaskData    ; Get the ID of the menu item selected.
  568.     sec    ; Turn it into an index by subtracting
  569.     sbc #250    ; the starting ID number (25) and mul-
  570.     asl a    ; tiplying by 2 (each table entry con-
  571.     tax    ; sists of 2 bytes).
  572.     jsr (MenuTable,x)    ; Call the routine behind it.
  573.  
  574.     PushWord #0    ; Routine done - unhilite the menubar.
  575.     PushWord TaskData+2
  576.     _HiLiteMenu
  577.  
  578.     rts
  579.  
  580. MenuTable    dc.W Ignore    ; undo
  581.     dc.W doCut    ; cut
  582.     dc.W doCopy    ; copy
  583.     dc.W doPaste    ; paste
  584.     dc.W doClear    ; clear
  585.     dc.W Ignore    ; close
  586.     dc.W doAbout
  587.     dc.W doQuit
  588.     ENDP
  589.  
  590.     EJECT
  591. *******************************************************************************
  592. *
  593. Ignore    PROC
  594. *
  595. * Description:    Called when I want to ignore an event.
  596. *
  597. *
  598. * Inputs:    NONE
  599. *
  600. * Outputs:    NONE
  601. *
  602. * External Refs:    NONE
  603. *
  604. * Entry Points:    NONE
  605. *
  606. *******************************************************************************
  607.  
  608.     rts
  609.     ENDP
  610.  
  611.     EJECT
  612. *******************************************************************************
  613. *
  614. doUpdate    PROC
  615. *
  616. * Description:    Called by the Main Event Loop to update a window's
  617. *    contents.
  618. *
  619. *
  620. * Inputs:    NONE
  621. *
  622. * Outputs:    NONE
  623. *
  624. * External Refs:    NONE
  625. *
  626. * Entry Points:    NONE
  627. *
  628. *******************************************************************************
  629.     with Globals
  630.  
  631.     lda WindPointer    ; first test to see that its our window
  632.     ora WindPointer+2
  633.     beq NotUp    ; bad bad update event!
  634.  
  635.     PushLong WindPointer ; Prepare to update our window
  636.     _BeginUpdate
  637.  
  638.     PushLong WindPointer ; draw all of the controls
  639.     _DrawControls
  640.  
  641.     PushLong #viewRect    ; frame our lineEdit item
  642.     _FrameRect
  643.  
  644.     PushLong LEHandle    ; update the LineEdit item
  645.     _LEUpdate
  646.  
  647.     PushLong WindPointer ; end updating of our window
  648.     _EndUpdate
  649.  
  650. NotUp
  651.     rts
  652.     ENDP
  653.  
  654.     EJECT
  655. *******************************************************************************
  656. *
  657. doActivate    PROC
  658. *
  659. * Description:    This routine is called when our window is either coming
  660. *    to front, or no longer being in front. Its main function
  661. *    is to make the LineEdit item (in)active.
  662. *
  663. *
  664. * Inputs:    Event record from TaskMaster
  665. *
  666. * Outputs:    NONE
  667. *
  668. * External Refs:    NONE
  669. *
  670. * Entry Points:    NONE
  671. *
  672. *******************************************************************************
  673.     With Globals
  674.  
  675.     PushLong LEHandle
  676.     lda EventModifiers
  677.     and #activeFlag
  678.     bne Activate
  679.     _LEDeactivate
  680.     bra done
  681. Activate    _LEActivate
  682. done
  683.     rts
  684.     ENDP
  685.  
  686.     EJECT
  687. *******************************************************************************
  688. *
  689. doKey    PROC
  690. *
  691. * Description:    Called by the Main Event loop when a Keydown or AutoKey
  692. *    Event occurs. If the RETURN key was hit, a hit on the
  693. *    "New Item" button is simulated. Otherwise, the key press
  694. *    is passed on to LEKey.
  695. *
  696. *
  697. * Inputs:    Event record from TaskMaster
  698. *
  699. * Outputs:    LineEdit or List is modified
  700. *
  701. * External Refs:    
  702.     import NewListItem
  703.     import ckNewAndRep
  704. *
  705. * Entry Points:    NONE
  706. *
  707. *******************************************************************************
  708.     with Globals
  709.  
  710.     lda EventMessage    ; get the character pressed
  711.     and #$007f    ; clear the high if it's set
  712.     cmp #$0D    ; see if it's a <RETURN> 
  713.     beq doCR    ; if is one, simulate New Item hit
  714.     PushWord EventMessage ; else, pass this on to LEKey
  715.     PushWord EventModifiers
  716.     PushLong LEHandle
  717.     _LEKey
  718.  
  719.     jsr ckNewAndRep    ; update the New and Replace buttons
  720.     bra done
  721.  
  722. doCR
  723.     PushWord #1    ; Hilite the New button
  724.     PushLong NewBHdl
  725.     _HiLiteControl
  726.  
  727.     PushWord #0    ; UnHilite the New button
  728.     PushLong NewBHdl
  729.     _HiLiteControl
  730.  
  731.     jsr NewListItem    ; add the LineEdit text to the list.
  732.  
  733. done
  734.     rts
  735.     ENDP
  736.  
  737.     EJECT
  738. *******************************************************************************
  739. *
  740. doEdit    PROC
  741. *
  742. * Description:    This block is really 4 routines to handle the Edit Menu.
  743. *    Any Edit selections are passed on to the appropriate
  744. *    LineEdit routine. Undo is currently not supported.
  745. *
  746. *
  747. * Inputs:    NONE
  748. *
  749. * Outputs:    NONE
  750. *
  751. * External Refs:
  752.     import ckNewAndRep
  753. *
  754. * Entry Points:
  755.     entry doCut
  756.     entry doCopy
  757.     entry doPaste
  758.     entry doClear
  759. *
  760. *******************************************************************************
  761.     with Globals
  762.  
  763. doCut    PushLong LEHandle    ; Handle a "Cut" command
  764.     _LECut
  765.     bra done
  766.  
  767. doCopy    PushLong LEHandle    ; Handle a "Copy" command
  768.     _LECopy
  769.     rts    ; Don't update New and Replace buttons
  770.  
  771. doPaste    PushLong LEHandle    ; Handle a "Paste" command
  772.     _LEPaste
  773.     bra done
  774.  
  775. doClear    PushLong LEHandle    ; Handle a "Clear" command
  776.     _LEDelete
  777.  
  778. done
  779.     jsr ckNewAndRep    ; update the New and Replace buttons
  780.  
  781.     rts
  782.     ENDP
  783.  
  784.     EJECT
  785. *******************************************************************************
  786. *
  787. InContent    PROC
  788. *
  789. * Description:    Called to handle clicks in a window's contents. FindControl
  790. *    is called to determine on what, if any, control was hit.
  791. *    If a control is hit, it is tracked, and the appropriate
  792. *    routine is called to perform some action. If a control
  793. *    is not hit, then a check is made to see if the LineEdit
  794. *    item was hit. If so, then the click is passed on to LEClick
  795. *    for handling.
  796. *
  797. *
  798. * Inputs:    NONE
  799. *
  800. * Outputs:    NONE
  801. *
  802. * External Refs:
  803.     import NewListItem
  804.     import DelListItem
  805.     import RepListItem
  806.     import RstListItem
  807.     import ListHit
  808.     import SortHit
  809. *
  810. * Entry Points:    NONE
  811. *
  812. *******************************************************************************
  813.     with Globals
  814.  
  815. ; First, find out where we clicked, and see if it was on a control
  816.  
  817.     pha    ; result space
  818.     PushLong #TempHndl
  819.     PushLong EventWhere    ; push the point
  820.     PushLong WindPointer
  821.     _FindControl
  822.     pla
  823.     bne IC0010    ; hit a control! Track it!
  824.     brl ckLine    ; didn't hit control. See if we hit LE
  825. IC0010
  826.     pha    ; result space
  827.     PushLong EventWhere    ; push mouse location
  828.     PushLong #-1    ; use default action procedure
  829.     PushLong TempHndl    ; push on handle to control hit
  830.     _TrackControl    ; track it
  831.     pla    ; where did we end up?
  832.     bne IC0020    ; still in control. Do something
  833.     brl done    ; out of control - exit this routine
  834. IC0020
  835.     cmp #simpleButton    ; was it a button?
  836.     beq CallCtlAction    ; if so then handle it
  837.     cmp #$88    ; was it the list itself?
  838.     bne done    ; if not, then not a hit!
  839.  
  840. ; We use a neat trick to determine what routine to call inresponse to a
  841. ; click on a control. We keep a 'routine index' in the refcon field of
  842. ; the control. When a click occurs on that control, we retrieve the
  843. ; refcon, turn it into an index into a table of routine pointers, get
  844. ; the pointer to a routine, and call it!
  845.  
  846. CallCtlAction
  847.     pha    ; space for result
  848.     pha
  849.     PushLong TempHndl    ; get the item number from the refcon
  850.     _GetCtlRefCon
  851.     pla    ; low byte of ref con
  852.     plx    ; (we don't use high byte)
  853.     dec a    ; subtract 1 from the refcon then
  854.     asl a    ; multiply by two to get table offset
  855.     tax
  856.     jsr (InCTable,x)    ; jump to routine to handle this ctl
  857.     bra done
  858.  
  859. ; the mouse click did not occur in any of the regular controls. check to
  860. ; see if we clicked in the LineEdit item. If so, then call LEClick.
  861.  
  862. ckLine
  863.     lda EventWhere    ; Check to see if we clicked in the
  864.     sta LocalPt    ; LineEdit item. We do this by doing a
  865.     lda EventWhere+2    ; PtInRect. But we need the mouse in
  866.     sta LocalPt+2    ; local coordinates for this.
  867.  
  868.     PushLong #LocalPt
  869.     _GlobalToLocal
  870.  
  871.     pha    ; space for result
  872.     PushLong #LocalPt
  873.     PushLong #destRect
  874.     _PtInRect    ; see if we clicked in the edit item
  875.     pla
  876.     beq done    ; no, we didn't, so leave
  877.  
  878.     PushLong #EventRecord ; yes we did, so call LEClick
  879.     PushLong LEHandle
  880.     _LEClick
  881.  
  882. done    rts
  883.  
  884. theRefCon    ds.B 4
  885. InCTable    dc.W NewListItem,DelListItem,RepListItem
  886.     dc.w RstListItem,ListHit,SortHit
  887. LocalPt    ds.b 4
  888.  
  889.     ENDP
  890.  
  891.     EJECT
  892. *******************************************************************************
  893. *
  894. NewListItem    PROC
  895. *
  896. * Description:    This routine is called by InContent if a click occured
  897. *    on the "New" button. This routine determines is there
  898. *    is enough room in the List record for another item. If
  899. *    so, then a pointer to the next record is is created, and
  900. *    AddMember is called to create a new List member using
  901. *    the text from the LineEdit item. When that is done, we
  902. *    tell the List Manager about it, and hilite the LineEdit
  903. *    text so that it is easily changed into something else.
  904. *
  905. *
  906. * Inputs:    NONE
  907. *
  908. * Outputs:    List updated. LineEdit text hilited.
  909. *
  910. * External Refs:
  911.     import AddMember
  912. *
  913. * Entry Points:    NONE
  914. *
  915. *******************************************************************************
  916.     With Globals
  917.  
  918.     lda MLNum    ; # of elements in the list
  919.     cmp #30    ; do we have 30 already?
  920.     bge NLIDone
  921.     inc MLNum    ; bump number of list entries
  922.  
  923. ; Create a pointer to the next available space in the array of list record.
  924. ; This is done by multiplying the entry number the entry size. Multiplying
  925. ; is done by using the formula x = index*2 + index*8 (assuming that the size
  926. ; of a member record = 10)
  927.  
  928.     asl a    ; multiply by 2
  929.     sta TempWord    ; save it for adding to *8 later
  930.     asl a    ; by four
  931.     asl a    ; and eight
  932.     clc
  933.     adc TempWord    ; add in the times 2 part
  934.  
  935. ; AddMember is the routine that we use to assign the text of the LineEdit
  936. ; item to a certain list record. All we have to do is enter with the
  937. ; accumulator holding a pointer to the right record, and it does the rest.
  938.  
  939.     jsr AddMember    ; enter with record offset in Acc.
  940.  
  941. ; Now tell the List Manager that we changed the list. Also, make sure that
  942. ; the item that is hilited in the list is STILL hilited. Do this by getting
  943. ; a pointer to the selected record, and passing it to _NewList
  944.  
  945.     pha    ; long space for result
  946.     pha
  947.     PushLong #0    ; start searching from the beginning
  948.     PushLong #MyList
  949.     _NextMember    ; Get pointer Keep it on the stack
  950.     PushLong #MyList    ; pointer to my list record
  951.     _NewList    ; and make the new list!
  952.  
  953. ; finally, hilite the line edit text so that we can easily change it later
  954.  
  955.     PushWord #0    ; starting hilite range
  956.     PushWord #255    ; ending range
  957.     PushLong LEHandle    ; hande to the LE control
  958.     _LESetSelect    ; hilite it.
  959.  
  960. NLIDone
  961.     rts
  962.  
  963.     ENDP
  964.  
  965.     EJECT
  966. *******************************************************************************
  967. *
  968. DelListItem    PROC
  969. *
  970. * Description:    Called by InContent to remove a member from the list. It
  971. *    is called only when there is a hilited list item to be
  972. *    removed. This routine determines which item is hilited,
  973. *    removes it from the list of member records, decrements
  974. *    the number of members in the list, and redraws the list.
  975. *
  976. *
  977. * Inputs:    NONE
  978. *
  979. * Outputs:    NONE
  980. *
  981. * External Refs:
  982.     import DisposeMember
  983.     import NoSelection
  984.     import ckNewAndRep
  985. *
  986. * Entry Points:    NONE
  987. *
  988. *******************************************************************************
  989.     With Globals
  990.  
  991.     lda MLNum    ; contains # of elements
  992.     cmp #1    ; do we have only 1 left?
  993.     beq DLIDone    ; if so then remove no more!
  994.     dec MLNum    ; adjust number of list entries
  995.  
  996. ; DisposeMember finds the hilited list item, and puts an index to it in the
  997. ; X register. Also, if the string for the name of the member was stored in
  998. ; a handle, that handle is disposed of.
  999.  
  1000.     jsr DisposeMember    ; X set up for us on exit
  1001.  
  1002. loop
  1003.     lda MyData+MemberSize,x
  1004.     sta MyData,x    ; move all data down 10 bytes
  1005.     inx    ; ...in memory...
  1006.     inx    ; ...two bytes at a time
  1007.     cpx #MyDataTSize    ; is X bumped past the end of records?
  1008.     blt loop    ; nope, keep looping
  1009.  
  1010.     PushLong #0    ; Draw All members to redraw the list!
  1011.     PushLong #MyList
  1012.     _NewList    ; and create the new list!
  1013.  
  1014.     jsr NoSelection    ; now reset the apropriate buttons
  1015.  
  1016. DLIDone
  1017.     jsr ckNewAndRep
  1018.     rts
  1019.  
  1020.     ENDP
  1021.  
  1022.     EJECT
  1023. *******************************************************************************
  1024. *
  1025. RepListItem    PROC
  1026. *
  1027. * Description:    This routine is called from InContent to replace the text
  1028. *    of the hilited member with the text in the LineEdit Item.
  1029. *    It calls NextMember to find the hilited item, Disposes of
  1030. *    it, and then inserts a new item in the same place with the
  1031. *    new name.
  1032. *
  1033. *
  1034. * Inputs:    NONE
  1035. *
  1036. * Outputs:    NONE
  1037. *
  1038. * External Refs:
  1039.     import DisposeMember
  1040.     import AddMember
  1041.     import NoSelection
  1042. *
  1043. * Entry Points:    NONE
  1044. *
  1045. *******************************************************************************
  1046.     With Globals
  1047.  
  1048.     pha    ; space for result
  1049.     pha
  1050.     PushLong #0    ; member to start looking at
  1051.     PushLong #MyList    ; NOTE: This is the list template ptr
  1052.     _NextMember
  1053.     PullLong TempLong    ; Pointer to item Selected
  1054.  
  1055. ;
  1056. ; Now that we know which member is being replaced, call DisposeMember to free
  1057. ; up the memory that is allocated to it, and then call AddMember to fill in that
  1058. ; member's record with new information.
  1059. ;
  1060.     jsr DisposeMember
  1061.     txa
  1062.     jsr AddMember
  1063.     
  1064. ; The information for the currently selected member has been changed. Now
  1065. ; redraw the member.
  1066.  
  1067.     PushLong TempLong    ; pass ptr of member to redraw
  1068.     PushLong #MyList
  1069.     _DrawMember
  1070.  
  1071.     jsr NoSelection    ; now reset the apropriate buttons
  1072.  
  1073. ; finally, hilite the line edit text so that we can easily change it later
  1074.  
  1075.     PushWord #0    ; starting hilite range
  1076.     PushWord #255    ; ending range
  1077.     PushLong LEHandle    ; hande to the LE control
  1078.     _LESetSelect    ; hilite it.
  1079.  
  1080.     rts
  1081.     ENDP
  1082.  
  1083.     EJECT
  1084. *******************************************************************************
  1085. *
  1086. RstListItem    PROC
  1087. *
  1088. * Description:    This routine is called by InContent to unhilite, or reset,
  1089. *    the currently selected item. It simply calls ResetMember
  1090. *    and then redraws that member.
  1091. *
  1092. *
  1093. * Inputs:    NONE
  1094. *
  1095. * Outputs:    NONE
  1096. *
  1097. * External Refs:    
  1098.     import NoSelection
  1099. *
  1100. * Entry Points:    NONE
  1101. *
  1102. *******************************************************************************
  1103.     With Globals
  1104.  
  1105.     pha    ; space for result
  1106.     pha
  1107.     PushLong #MyList    ; NOTE: This Is the list template ptr
  1108.     _ResetMember    ; get item selected & unselect it
  1109.     PullLong TempLong    ; Item Selected
  1110.  
  1111. ; Obviously, at this point we could have omitted the PullLong/PushLong
  1112. ; sequence to save some bytes, but we wanted to make sure that people were
  1113. ; clear on what ResetMember returned, and what was passed to DrawMember.
  1114.  
  1115.     PushLong TempLong    ; pass ptr of member to redraw
  1116.     PushLong #MyList    ; now redraw the list
  1117.     _DrawMember
  1118.  
  1119.     jsr NoSelection    ; turn off those buttons
  1120.     rts
  1121.     ENDP
  1122.  
  1123.     EJECT
  1124. *******************************************************************************
  1125. *
  1126. ListHit    PROC
  1127. *
  1128. * Description:    This routine is called by InContent when a hit on the List
  1129. *    item has occured. It activates the buttons we need when a
  1130. *    list item is selected, and gets the text of the item and
  1131. *    puts it into the LineEdit box. Finally, it hilites the
  1132. *    LineEdit text so that we can easily change it if we want.
  1133. *
  1134. *
  1135. * Inputs:    NONE
  1136. *
  1137. * Outputs:    NONE
  1138. *
  1139. * External Refs:    NONE
  1140. *
  1141. * Entry Points:    NONE
  1142. *
  1143. *******************************************************************************
  1144.     With Globals
  1145.  
  1146.     PushWord #0    ; activate the delete button
  1147.     PushLong DelBHdl    ; handle to the delete button
  1148.     _HiLiteControl
  1149.  
  1150.     PushWord #255    ; now deactivate the replace button
  1151.     PushLong RepBHdl    ; until we change edit item
  1152.     _HiLiteControl
  1153.  
  1154.     PushWord #0    ; now activate the replace button
  1155.     PushLong RstBHdl
  1156.     _HiLiteControl
  1157.  
  1158. ;
  1159. ; Find out which member we hit, and insert its text into Line Edit
  1160. ;
  1161.     pha    ; space for result
  1162.     pha
  1163.     PushLong #0    ; NIL to start at first entry
  1164.     PushLong #MyList    ; pointer to my list record...
  1165.     _NextMember
  1166.     PullLong deref    ; pointer to the next record
  1167.  
  1168.     ldy #2    ; get the pointer to the string. We do
  1169.     lda [deref],y    ; this by getting the pointer that the
  1170.     tax    ; handle points to, and storing it back
  1171.     lda [deref]    ; out in 'deref'.
  1172.     sta deref
  1173.     stx deref+2
  1174.  
  1175.     PushWord deref+2    ; push on a pointer to the first character
  1176.     lda deref
  1177.     ina
  1178.     pha
  1179.     lda [deref]    ; get the length of the string
  1180.     and #$00FF
  1181.     pha    ; push on the length
  1182.     PushLong LEHandle
  1183.     _LESetText
  1184.     
  1185. ; Now invalidate the area of the screen that contained the text so that
  1186. ; LineEdit will redraw it.
  1187.  
  1188.     PushLong #destRect
  1189.     _InvalRect
  1190.  
  1191. ; finally, hilite the line edit text so that we can easily change it later
  1192.  
  1193.     PushWord #0    ; starting hilite range
  1194.     PushWord #255    ; ending range
  1195.     PushLong LEHandle    ; hande to the LE control
  1196.     _LESetSelect    ; hilite it.
  1197.  
  1198.     rts
  1199.     ENDP
  1200.  
  1201.     EJECT
  1202. *******************************************************************************
  1203. *
  1204. SortHit    PROC
  1205. *
  1206. * Description:    This routine is called by InCotent when a click on the
  1207. *    Sort button occurs. It calls _SortList with a pointer to
  1208. *    a custom sorting routine, and then redraws the entire list.
  1209. *    The custom sorting procedure sorts the list in reverse
  1210. *    alphabetical order.
  1211. *
  1212. *
  1213. * Inputs:    NONE
  1214. *
  1215. * Outputs:    NONE
  1216. *
  1217. * External Refs:    NONE
  1218. *
  1219. * Entry Points:    NONE
  1220. *
  1221. *******************************************************************************
  1222.     With Globals
  1223.  
  1224.     PushLong #MySort    ; Case insensitive sort routine
  1225.     PushLong #MyList
  1226.     _SortList
  1227.  
  1228.     PushLong #0    ; redraw all members
  1229.     PushLong #MyList
  1230.     _DrawMember
  1231.  
  1232.     rts
  1233.  
  1234. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1235. ;
  1236. MySort
  1237. ;
  1238. ; This is the custom sorting routine. It is passed the pointers to
  1239. ; 2 member records to compare. If the first member is 'less than' the
  1240. ; second, then return with the carry set. Otherwise, the carry should
  1241. ; be returned clear. When I am done, remove the parameters off of the
  1242. ; stack and RTL back to the List Manager.
  1243. ;
  1244. ; The following are equates that I use for a 'local direct page'. I
  1245. ; save off the register that points to the normal direct page, and
  1246. ; put the value of the stack pointer into the Direct Page register.
  1247. ; This way, the stack doubles as my direct page, and I can easily
  1248. ; access the variables that were pushed on it. These equates repre-
  1249. ; sent the information on the stack when my routine is called.
  1250. ; Specifically, there is a 3 byte return address that will get me
  1251. ; back to the list manager, and then there are 2 4-byte parameters
  1252. ; that are pointers to the 2 members I have to compare.
  1253. ;
  1254. RTLAddr    equ 1
  1255. MemberA    equ RTLAddr+3
  1256. MemberB    equ MemberA+4
  1257.  
  1258.     tsc    ; save the old Direct Page and
  1259.     phd    ; make the stack our DP so that
  1260.     tcd    ; we can use the params as pointers
  1261.  
  1262.     ldy #2    ; replace the pointer to the first
  1263.     lda [MemberA],y    ; member with the pointer to the
  1264.     tax    ; string of that member.
  1265.     lda [MemberA]
  1266.     sta MemberA
  1267.     stx MemberA+2
  1268.  
  1269.     lda [MemberB],y    ; do the same thing with the second
  1270.     tax    ; member.
  1271.     lda [MemberB]
  1272.     sta MemberB
  1273.     stx MemberB+2
  1274.  
  1275.     SHORTMX    ; Use 8-bit registers
  1276.  
  1277.     ldy #1    ; Start comparing with char #1
  1278. cmpLoop
  1279.     lda [MemberB],y    ; Now compare the string characters.
  1280.     jsr upperIt
  1281.     sta firstChar
  1282.     lda [MemberA],y    
  1283.     jsr upperIt
  1284.     cmp firstChar    ; If they are not equal, exit with the
  1285.     bne done    ; carry is set appropriately.
  1286.  
  1287.     tya    ; Check to see if we ended a string
  1288.     dec a
  1289.     cmp [MemberB]    ; end of Member B?
  1290.     beq AGreater    ; if so, exit with carry set.
  1291.  
  1292.     cmp [MemberA]    ; end of Member A?
  1293.     beq BGreater    ; if so, exit with carry clear.
  1294.  
  1295.     iny    ; bump index to examine next char.
  1296.     bra cmpLoop
  1297.  
  1298. AGreater    clc
  1299.     bra done
  1300. BGreater    sec
  1301. done    LONGMX
  1302.  
  1303.     pld    ; restore the Direct Page reg from stack.
  1304.  
  1305.     lda 0,s    ; move the RTL address up so that it is
  1306.     sta 8,s    ; in the right place after we remove the
  1307.     lda 2,s    ; parameters.
  1308.     sta 10,s
  1309.     pla    ; remove the pointers to the members from
  1310.     pla    ; the stack.
  1311.     pla
  1312.     pla
  1313.     rtl
  1314.  
  1315.     longa off
  1316. upperIt    cmp #'z'+1
  1317.     bcs @a
  1318.     cmp #'a'
  1319.     bcc @a
  1320.     sbc #32
  1321. @a    rts
  1322.     longa on
  1323.  
  1324. firstChar    dc.b 0
  1325.  
  1326.     ENDP
  1327.  
  1328.     EJECT
  1329. *******************************************************************************
  1330. *
  1331. ckNewAndRep    PROC
  1332. *
  1333. * Description:    Called from all over the place to correctly set the
  1334. *    activation states of the New and Replace buttons.
  1335. *
  1336. *
  1337. * Inputs:    NONE
  1338. *
  1339. * Outputs:    NONE
  1340. *
  1341. * External Refs:    NONE
  1342. *
  1343. * Entry Points:    NONE
  1344. *
  1345. *******************************************************************************
  1346.     with Globals
  1347.  
  1348. ; Disable the replace button if no items are selected
  1349.  
  1350.     pha    ; long space for result
  1351.     pha
  1352.     PushLong #0    ; start searching from the beginning
  1353.     PushLong #MyList
  1354.     _NextMember
  1355.     pla    ; was a pointer returned (if a long
  1356.     sta TempWord    ; zero is return, there are not items
  1357.     pla    ; selected).
  1358.     ora TempWord
  1359.     beq DisableRepItem
  1360.  
  1361.     PushWord #0    ; activate the replace button
  1362.     bra FixRepButton
  1363.  
  1364. DisableRepItem
  1365.     PushWord #255    ; deactivate the replace button
  1366.  
  1367. FixRepButton
  1368.     PushLong RepBHdl
  1369.     _HiLiteControl
  1370.  
  1371. ; Enable or disable the New entry button depending on whether or not there
  1372. ; is any text in the LineEdit buffer.
  1373.  
  1374.     pha
  1375.     PushLong LEHandle
  1376.     _LEGetTextLen
  1377.     pla
  1378.     beq disableIt    ; if no length, then no text.
  1379.  
  1380.     PushWord #0    ; activate the New button
  1381.     bra CallHilite
  1382.  
  1383. disableIt
  1384.     PushWord #255    ; deactivate the New button
  1385.  
  1386. CallHilite
  1387.     PushLong NewBHdl
  1388.     _HiLiteControl
  1389.  
  1390.     RTS
  1391.     ENDP
  1392.  
  1393.     EJECT
  1394. *******************************************************************************
  1395. *
  1396. AddMember    PROC
  1397. *
  1398. * Description:    Utility routine called from NewListItem and RepListItem to
  1399. *    insert a new member. This routine will read the entry in
  1400. *    the LineEdit record, store it in a handle, and create a
  1401. *    new member record at the spot that is specified by the
  1402. *    accumulator. It does not redraw the list.
  1403. *
  1404. *
  1405. * Inputs:    A = the offset to the record that you want to change.
  1406. *
  1407. * Outputs:    X = the offset to the record that was changed.
  1408. *
  1409. * External Refs:    NONE
  1410. *
  1411. * Entry Points:    NONE
  1412. *
  1413. *******************************************************************************
  1414.     with Globals
  1415.  
  1416.     sta RecordIndex
  1417.  
  1418.     pha    ; space for handle
  1419.     pha
  1420.     PushLong LEHandle
  1421.     _LEGetTextHand    ; get the text from Line Edit
  1422.     PullLong TempHandle
  1423.  
  1424.     pha
  1425.     PushLong LEHandle
  1426.     _LEGetTextLen    ; find out how large it is.
  1427.     PullWord StringSize
  1428.  
  1429.     pha    ; make room for NewHandle result
  1430.     pha
  1431.     PushWord #0    ; push handle size that we want
  1432.     lda StringSize    ; but add 1 to it to take into
  1433.     inc a    ; account the string length byte
  1434.     pha
  1435.     PushWord MyID
  1436.     PushWord #attrFixed+attrNoCross
  1437.     PushLong #0
  1438.     _NewHandle    ; create a handle for the string
  1439.  
  1440. ; save the handle we got in 'StringHandle' so that we can later store it in the
  1441. ; member's record. Also store it in 'deref' so that we can dereference it. The
  1442. ; macro PullLong addr1,addr2 will do that for us in one step!
  1443.  
  1444.     PullLong StringHandle,deref
  1445.  
  1446.     ldy #2    ; dereference the String Handle to get
  1447.     lda [deref],y    ; just a pointer.
  1448.     tax
  1449.     lda [deref]
  1450.     sta deref
  1451.     stx deref+2
  1452.  
  1453.     lda StringSize    ; create a Pascal string from the lineEdit
  1454.     sta [deref]    ; item for the List Manager
  1455.  
  1456. ; Copy the LineEdit string into the string's handle. However, set the
  1457. ; destination to be the second byte of the handle, as we need to put the
  1458. ; length of the string in the first byte.
  1459.  
  1460.     PushLong TempHandle    ; handle of the source string
  1461.     lda deref+2    ; deref holds a pointer to the start
  1462.     pha    ; of the destination, but we have to bump
  1463.     lda deref    ; by one to account for the length byte
  1464.     inc a    ; that we have to stick there.
  1465.     pha
  1466.     PushWord #0    ; bytes to transfer must be LONG, so
  1467.     PushWord StringSize    ; create a high byte of zero.
  1468.     _HandToPtr
  1469.  
  1470. ; initialize the data in the member record we are creating.
  1471.  
  1472.     ldx RecordIndex
  1473.     lda deref    ; get low word of address of new string
  1474.     sta MyData,x    ; and save it
  1475.     lda deref+2    ; and now the high word
  1476.     sta MyData+2,x
  1477.     lda #0    ; store a memflag byte
  1478.     sta MyData+4,x
  1479.     lda StringHandle    ; store the handle to the string so that
  1480.     sta MyData+6,x    ; we can easily dispose of it later.
  1481.     lda StringHandle+2
  1482.     sta MyData+8,x
  1483.  
  1484.     rts
  1485.  
  1486. StringHandle    ds.b 4
  1487. TempHandle    ds.b 4
  1488. StringSize    ds.b 2
  1489. RecordIndex    ds.b 2
  1490.  
  1491.     ENDP
  1492.  
  1493.     EJECT
  1494. *******************************************************************************
  1495. *
  1496. DisposeMember    PROC
  1497. *
  1498. * Description:    Find the currently hilited list member and and return
  1499. *    with an offset to it. Will also dispose of any memory
  1500. *    associated with it to hold the displayed text.
  1501. *
  1502. *
  1503. * Inputs:    NONE
  1504. *
  1505. * Outputs:    X = offset from start of Member record array where the
  1506. *        currently hilited member is stored.
  1507. *
  1508. * External Refs:    NONE
  1509. *
  1510. * Entry Points:    NONE
  1511. *
  1512. *******************************************************************************
  1513.     with Globals
  1514.  
  1515. ; Call _NextMember to find the hilited item. Calculate the offset
  1516. ; within MyData of that record, and dispose of any string handles
  1517. ; that may be there.
  1518.  
  1519.     pha    ; space for result
  1520.     pha
  1521.     PushLong #0    ; NIL to start at first entry
  1522.     PushLong #MyList    ; pointer to my list record.
  1523.     _NextMember
  1524.     pla    ; pointer to the next record
  1525.     plx    ; discard the high byte
  1526.     sec    ; subtract the front of the list to
  1527.     sbc #MyData    ; get the offset into the table
  1528.     tax    ; put into X so we can adjust the list
  1529.     stx RecordIndex    ; save it here for when we exit
  1530.  
  1531.     lda MyData+6+2,x    ; See if there's a string handle by
  1532.     ora MyData+6,x    ; checking for a NULL handle.
  1533.     beq done    ; no string - so nothing to dispose of
  1534.  
  1535.     PushLong MyData+6,x    ; get the string handle and dispose of it
  1536.     _DisposeHandle
  1537. done
  1538.     ldx RecordIndex    ; return with offset in X register.
  1539.     rts
  1540.  
  1541. RecordIndex    ds.b 2
  1542.  
  1543.     ENDP
  1544.  
  1545.  
  1546.     EJECT
  1547. *******************************************************************************
  1548. *
  1549. NoSelection    PROC
  1550. *
  1551. * Description:    Set the activation state of the buttons to reflect the
  1552. *    fact that no list items are selected.
  1553. *
  1554. *
  1555. * Inputs:    NONE
  1556. *
  1557. * Outputs:    NONE
  1558. *
  1559. * External Refs:    NONE
  1560. *
  1561. * Entry Points:    NONE
  1562. *
  1563. *******************************************************************************
  1564.     With Globals
  1565.  
  1566.     PushWord #255    ; deactivate the delete button
  1567.     PushLong DelBHdl    ; handle to the delete button
  1568.     _HiLiteControl
  1569.  
  1570.     PushWord #255    ; deactivate the reset button
  1571.     PushLong RstBHdl
  1572.     _HiLiteControl
  1573.  
  1574.     PushWord #255    ; deactivate the replace button
  1575.     PushLong RepBHdl
  1576.     _HiLiteControl
  1577.  
  1578.     rts
  1579.     ENDP
  1580.  
  1581.     EJECT
  1582. *******************************************************************************
  1583. *
  1584. CreateCtrls    PROC
  1585. *
  1586. * Description:    Called at initialization time to create all of the
  1587. *    simple buttons we use.
  1588. *
  1589. *
  1590. * Inputs:    NONE
  1591. *
  1592. * Outputs:    NONE
  1593. *
  1594. * External Refs:    NONE
  1595. *
  1596. * Entry Points:    NONE
  1597. *
  1598. *******************************************************************************
  1599.     With Globals
  1600.  
  1601.     stz CCCount    ; zero our counter
  1602. CCLoop
  1603.     lda CCCount    ; get the next ctrl num to add
  1604.     asl a    ; multiply it by four to make it an
  1605.     asl a    ; offset into our control table
  1606.     tax    ; now use it as an index
  1607.     lda MyCtrlList,x    ; to get the pointer to the control data
  1608.     sta deref    ; and save it in the DPage
  1609.     lda MyCtrlList+2,x    ; so we can read it nicely
  1610.     sta deref+2
  1611.     stx TempWord    ; save x for a moment
  1612.  
  1613.     pha    ; space for result
  1614.     pha
  1615.     PushLong WindPointer ; pointer to my window
  1616.  
  1617. ; Push on NewControl parameters. These parameters are obtained from tables
  1618. ; in our Globals section. Each one is 'cRecSize' long, so we load the Y reg
  1619. ; with that value (less 2), and use it to access all of the parameters in 
  1620. ; the table, pushing each one on the stack as we go.
  1621.  
  1622.     ldy #cRecSize-2
  1623. CCL010    lda [deref],y    ; Get these parameters from a list of
  1624.     pha    ; data blocks in the Globals data
  1625.     dey    ; section.
  1626.     dey
  1627.     bpl CCL010    ; if not done, get the next one!
  1628.  
  1629.     _NewControl    ; if so, then just call new control!
  1630.  
  1631.     ldx TempWord    ; retrieve x
  1632.     pla    ; and save the control handle
  1633.     sta MyCtlHdls,x
  1634.     pla
  1635.     sta MyCtlHdls+2,x
  1636.  
  1637.     inc CCCount    ; bump counter to get next record
  1638.     lda CCCount
  1639.     cmp NumCtrls    ; test to see if we did the last one
  1640.     blt CCLoop    ; if so, then just end
  1641.  
  1642. ;
  1643. ; Create the LineEdit item.
  1644. ;
  1645.     pha    ; space for result
  1646.     pha
  1647.     PushLong #destRect
  1648.     PushLong #destRect
  1649.     PushWord #20    ; Allow only 20 chars in list item
  1650.     _LENew
  1651.     PullLong LEHandle
  1652.  
  1653.     rts
  1654.  
  1655. tempHandle    ds.B 4
  1656. CCCount    ds.B 2
  1657.  
  1658.     ENDP
  1659.  
  1660.     EJECT
  1661. *******************************************************************************
  1662. *
  1663. CreateList    PROC
  1664. *
  1665. * Description:    Called at initialization time to create the list item. It
  1666. *    simply calls _CreateList with a parameter block defined
  1667. *    in the Globals data section.
  1668. *
  1669. *
  1670. * Inputs:    NONE
  1671. *
  1672. * Outputs:    NONE
  1673. *
  1674. * External Refs:    NONE
  1675. *
  1676. * Entry Points:    NONE
  1677. *
  1678. *******************************************************************************
  1679.     With Globals
  1680.  
  1681.     pha    ; room for result
  1682.     pha
  1683.     PushLong WindPointer
  1684.     PushLong #MyList    ; pointer to list rec
  1685.     _CreateList
  1686.     PullLong ListCtlHndl ; and get our list control handle
  1687.  
  1688.     rts
  1689.     ENDP
  1690.  
  1691.     EJECT
  1692. *******************************************************************************
  1693. *
  1694. doQuit    PROC
  1695. *
  1696. * Description:    Quit routine. Set the QuitFlag to TRUE for the EventLoop.
  1697. *
  1698. *
  1699. * Inputs:    NONE
  1700. *
  1701. * Outputs:    QuitFlag set to $FFFF
  1702. *
  1703. * External Refs:    NONE
  1704. *
  1705. * Entry Points:    NONE
  1706. *
  1707. *******************************************************************************
  1708.     With Globals
  1709.  
  1710.     lda #$FFFF
  1711.     sta QuitFlag
  1712.     rts
  1713.     ENDP
  1714.  
  1715.     Include 'lists.inits.aii'
  1716.  
  1717.     END
  1718.  
  1719.